/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TestSpaceVisometry.java
 *
 * Created on Oct 20, 2009, 9:21:37 PM
 */
package org.bm.blaise.testing.space;

import data.propertysheet.PropertySheet;
import org.bm.blaise.sequor.timer.BetterTimeClock;
import org.bm.blaise.specto.plane.PlanePlotComponent;
import org.bm.blaise.specto.plane.PlaneVisometry;
import org.bm.blaise.specto.space.*;
import org.bm.blaise.specto.space.basic.SpaceBox;
import org.bm.blaise.specto.space.function.SpaceFunctionGraph;
import org.bm.blaise.specto.visometry.PlotComponent;
import org.bm.blaise.specto.visometry.Plottable;

/**
 *
 * @author ae3263
 */
public class TestSpaceVisometry extends javax.swing.JFrame {

    PlaneGraphicsInSpace pgis;
    PlaneVisometry pv;
    PlanePlotComponent ppc;
    BetterTimeClock timer;

    /** Creates new form TestSpaceVisometry */
    public TestSpaceVisometry() {
        data.propertysheet.editor.EditorRegistration.registerEditors();
        timer = new BetterTimeClock();
        initComponents();

        stdPlot.addPlottable(new SpaceAxes());
        stdPlot.addPlottable(new SpaceBox());
        miniPlot.addPlottable(new SpaceAxes());
        miniPlot.addPlottable(new SpaceViewObjects(((SpaceVisometry) stdPlot.getVisometry()).getProj()));

        funPlot.addPlottable(new SpaceAxes());
        funPlot.addPlottable(new SpaceFunctionGraph());

//        pv = new PlaneVisometry();
//        pgis = new PlaneGraphicsInSpace(planarPlot.getVisometryGraphics(), pv);
//        ppc = new PlanePlotComponent(pgis, pv);
//        planarPlot.getVisometry().addChangeListener(new ChangeListener(){
//            public void stateChanged(ChangeEvent e) {
//                ppc.repaint();
//                planarPlot.repaint();
//            }
//        });
//        planarPlot.addPlottable(new SpaceAxes());
//        ppc.addPlottable(new PlaneParametricCurve(new UnivariateVectorialFunction(){
//            public double[] value(double x) throws FunctionEvaluationException {
//                return new double[] { x*Math.cos(x), x*Math.sin(x) };
//            }
//        }, 0.0, 2*Math.PI, 100));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        stdPlot = new org.bm.blaise.specto.space.SpacePlotComponent();
        miniPlot = new org.bm.blaise.specto.space.SpacePlotComponent();
        funPlot = new org.bm.blaise.specto.space.SpacePlotComponent();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        rollupPanel1 = new gui.RollupPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        stdPlot.setBackground(new java.awt.Color(0, 0, 0));

        org.jdesktop.layout.GroupLayout miniPlotLayout = new org.jdesktop.layout.GroupLayout(miniPlot);
        miniPlot.setLayout(miniPlotLayout);
        miniPlotLayout.setHorizontalGroup(
            miniPlotLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 300, Short.MAX_VALUE)
        );
        miniPlotLayout.setVerticalGroup(
            miniPlotLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 200, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout stdPlotLayout = new org.jdesktop.layout.GroupLayout(stdPlot);
        stdPlot.setLayout(stdPlotLayout);
        stdPlotLayout.setHorizontalGroup(
            stdPlotLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, stdPlotLayout.createSequentialGroup()
                .addContainerGap(412, Short.MAX_VALUE)
                .add(miniPlot, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        stdPlotLayout.setVerticalGroup(
            stdPlotLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, stdPlotLayout.createSequentialGroup()
                .addContainerGap(396, Short.MAX_VALUE)
                .add(miniPlot, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Camera & View", stdPlot);

        funPlot.setBackground(new java.awt.Color(0, 0, 0));

        org.jdesktop.layout.GroupLayout funPlotLayout = new org.jdesktop.layout.GroupLayout(funPlot);
        funPlot.setLayout(funPlotLayout);
        funPlotLayout.setHorizontalGroup(
            funPlotLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 722, Short.MAX_VALUE)
        );
        funPlotLayout.setVerticalGroup(
            funPlotLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 607, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Function", funPlot);

        getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

        jToolBar1.setRollover(true);

        jButton1.setText("Toggle anaglyph view");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);

        jScrollPane1.setViewportView(rollupPanel1);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.EAST);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
        rollupPanel1.removeAll();
        PlotComponent ppc = (PlotComponent) jTabbedPane1.getSelectedComponent();
        rollupPanel1.add("Visometry", new PropertySheet(ppc.getVisometry()));
        rollupPanel1.add("Timer", new PropertySheet(timer));
        for (Object p : ppc.getPlottables()) {
            rollupPanel1.add(p.toString(), new PropertySheet(p));
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jTabbedPane1StateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        SpacePlotComponent spc = (SpacePlotComponent) jTabbedPane1.getSelectedComponent();
        spc.setAnaglyph(!spc.isAnaglyph());
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TestSpaceVisometry().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.bm.blaise.specto.space.SpacePlotComponent funPlot;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private org.bm.blaise.specto.space.SpacePlotComponent miniPlot;
    private gui.RollupPanel rollupPanel1;
    private org.bm.blaise.specto.space.SpacePlotComponent stdPlot;
    // End of variables declaration//GEN-END:variables
}
